#!/usr/bin/env node

const inquirer = require('inquirer')
const path = require('path')
const fs = require('fs')
const ejs = require('ejs')

const promptList = [
    {
        type: 'input',
        name: 'name',
        message: 'Your project name?',
        default: 'myProject'
    }
]

inquirer.prompt(promptList).then(answers => {
    const tempDir = path.join(__dirname, 'templates')
    const destDir = process.cwd()

    fs.readdir(tempDir, (err, files) => {
        if (err) throw err
        files.forEach(file => {
            ejs.renderFile(path.join(tempDir, file), answers, (err, res) => {
                fs.writeFileSync(path.join(destDir, file), res)
            })
        })
    })
})